package com.realestate.dao;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.realestate.model.LoginModel;

/**
 * @author sri
 * 
 */
/**
 * @author sri
 *
 */
public class LoginDao extends BaseDAO<LoginModel, Integer> {

	/**
	 * @param loginModel
	 * @return boolean
	 */
	public boolean validateLogin(LoginModel loginModel) {
		boolean result = false;
		LoginModel loginRes = findById(loginModel.getUserId());
		if (loginRes != null) {
			if (loginRes.getPassword().equals(loginModel.getPassword())) {
				result = true;
			}
		}
		return result;

	}

	
	/**
	 * @param args Tester method
	 * to test copy spring.xml and paste in the class path to access it.
	 */
	public static void main(String[] args) {
		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"spring.xml");

		LoginModel form = new LoginModel();

		form.setPassword("10");
		form.setUserId(1);

		new LoginDao().save(form);

		LoginModel form4 = new LoginDao().findById(1);
		System.out.println(form4.getPassword());
	}

	@Override
	protected Class<LoginModel> getEntityClass() {
		// TODO Auto-generated method stub
		return LoginModel.class;
	}
}
